I have this problem too. iMac M1 24", Monterey 12.3.1.
Every time the computer goes to sleep, upon wakeup, all windows revert to the screen with the menu bar.
Very frustrating.
This never happened on my old Mac mini Intel i7 running OS 11.x.x and earlier.
Clearly, a bug by Apple. Probably, upon re-start from sleep, the OS looks at what motors are available, does not (yet) see the second external monitor), and then places all the windows onto the main screen. Perhaps 0.5 seconds, later, the OS "wakes up" the external monitors, but by that time, the window locations have been reset.
It would seem that NOBODY at APPLE gives a **** about software QA on Macs with multiple monitors, beyond ensuring that they turn on (which is not always the case with the Mac mini... another long time bug over the past 3+ years for 100s / 1000s of mini owners, covering both i7 and M1 chips)