There is no problem as such with resizing a modal window, but there are a few points that may speak against it in some curcumstances:
Resizing maybe considered an "unexpected sied effect", and reduce the users feeling of being in control.
The dialog might be positioned near a screen border, resizing it may move parts off-screen and either force the user to drag it back, or force you to make it jump around.
(This is still better than forcing the user to resize manually - but only slightly so.)
Automatic resizing may create the impression of having jumped a different dialog, increasing perceived complexity.
Modal dialogs lock you in, they say "before you want to do anything else, complete this."
Keep this lock-in short! A task that requires frequent resizing of its canvas might not be well suited to a modal dialog.
There should be no need to "peek behind" that dialog. It might be the cleaner solution to go with the maximum reasonable size (as @VitalyMijiritsky already elaborated), and accept some blank space in the layout. Blank space isn't bad for modal tasks.
I do see use cases where resizing on the fly still would be useful, or where longer lock-in isn't really a problem. Adjusting the initial size to fit the initial/current content should be fine in most situations.
tl;dr: you can, but think twice if you need to