I used to have two otherwise identical displays, but it still does it for me now that all of my displays are different. Notably, I think this stuff happens more when you have 3+ monitors. I don't remember having as many issues with just two displays.
I never managed to actually fix it. Maybe the links in the sibling comment can be of help there. But I feel like it became less of a nuisance after Monterey. Nowadays, it seems to move my app windows between displays after sleep, but that is resolved by applying the window layout snapshot from Moom.
My exact script seems to be gone — goes to show that I've not needed it for a while now — but the gist of my workaround was:
• I set up my display arrangement the way I wanted,
• followed the instructions in the displayplacer repo to work out a command to reproduce the desired arrangement,
• put the displayplacer command and the AppleSript call to Moom in the same shell script, with a short sleep between the two,
• and created an Alfred action to make it a tiny bit more convenient for myself.
The display arrangement would get out of sorts, but getting it back to my liking was just an Alfred action away.
You don't have to use Alfred or Moom specifically, those are just the convenience utilities I prefer.
An Alfred action to run the displayplacer command and then after a second to activate my 'default' Moom window layout made for a great workaround.