I suffer from a very similar problem. My MacBook Pro (16-inch, 2021), with Apple M1 Max CPU and macOS Monterey 12.6, is similarly unreliable about assigning the left and right external monitors. They are both BenQ EX2780Q models. In my case, the Mac gets it right about 80% of the times it awakes from sleep. When it gets it wrong, I have a couple of workarounds which are usually effective. But it is very annoying.
My two monitors are side-by-side, above the MacBook Pro's built-in display. The left-hand monitor connects via Thunderbolt 3 cable to a Thunderbolt port on the left of the MacBook Pro. The right-hand monitor connects via an HDMI cable to an HDMI port on the right of the MacBook Pro. Normally, the Display Preferences UI labels the left-hand monitor "BenQ EX2780Q (1)", and the right-hand monitor "BenQ EX2780Q (2)".
What I observe is that, when the Mac wakes from sleep, or wakes the monitors from sleep after I have not used them in a while, there is a period of 5-15 seconds when the displays show messages or images, then go black, then display images again. Eventually both monitors show desktop images. I can move my pointer from built-in display to display (1) to display (2). About 80% of the time, the Mac picks the left-hand monitor to be display (1), and the right to be display (2). The rest of the time, it reverses this assignment.
I can tell which outcome I have, even before I enter my password to remove the display lock, by moving my pointer upwards from the built-in MacBook display to display (1). When things are correct, the pointer arrives on the left-hand monitor. When things are wrong, it arrives on the right-hand monitor.
In Display Preferences, macOS always depicts display (1) on the left and display (2) on the right, even when it has got them swapped in real life. I can confirm this by displaying different desktop images on each monitor. The Display Preferences UI shows the desktop images.
My primary workaround is, when the displays awake and before I enter my password to the display lock, to move the pointer up and sideways. This lets me tell if the displays are assigned in reverse. If they are, I press the "Cancel" button (or press the Escape key), and the displays go back to sleep. I wait a second and try again. It seems like the Mac rolls the dice on mis-assigning the displays each time it wakes. But, it has a bias to keep the assignment it currently has, even if it is wrong. Sometimes, the second try is correct. Sometimes I need to try 10 times.
If that fails, my second workaround is to unplug the cable to my right-hand monitor, the one I want to be display (2). Then I wake up the Mac. It has no choice but to make my left-hand monitor be display (1). Then I plug in the cable to my right-hand monitor. It becomes display (2), as I want it to be. The downside of this trick is that, once I unlock my screen, I usually discover that my application windows are on the wrong display.
I tried using displayplacer. It is "a command line utility to configure multi-display resolutions and arrangements." I got it via MacPorts. Displayplacer lets you assign display rotation, resolution, and relative position, using ID numbers which are supposed to be unique and unchanging. For instance, you could command (I shortened id numbers and added line breaks for clarity):
displayplacer "id:1817…1F30+F466…DECD res:1440x900 scaling:on origin:(0,0) degree:0"
"id:4C40…22BB res:768x1360 hz:60 color_depth:8 scaling:off origin:(1440,0) degree:90"
"id:A46D2F5E-487B-CC69-C588-ECFD519016E5 mode:3 origin:(-1440,0) degree:270"
What disappointed me about displayplacer is that those ID numbers are not attached to the physical monitors. Instead, they appear attached to macOS's idea of "display (1)" and "display (2)". When macOS reverses the assignments, it reverses the relationship of ID number to physical monitor as well. I suppose I could come up with two scripted invocations of displayplacer: one to reverse relative positions of the displays in response to macOS reversing the assignments, and one to correctly position the displays in response to macOS later getting the assignments right. I will leave someone else to write the answer which shows how to do this.