I had this same annoying problem for a very long time.
I especially had problems with Steam games (Art of Ralley specifically)
Today, I found out about "Controlly", an App from the Apple Store.
Currently, I have installed the 7-day demo. I havn't figured out yet, what the full version cost.
However, when I installed Controlly, I had to go to some system settings to allow Controlly to "control the computer". I had to open a lock, to set the checkmark at Controlly.
In the same step, I noticed that Steam was also in that list ("allow to control the computer").
I set the checkmark aslo for Steam.
Now, my Playstation 5 Controller is just working... Just like that... I was trying that for years now (bought my M1 in April 2021). I don't know, if it was Controlly or the missing checkmark for Steam... But now it is just working... I'm speechless how easy that was. I'm equally speechless, that this is not just working "out of the box"....
Try it and it would be nice if somebody could report if the missing check mark for Steam would have been enough. I WILL NOT TOUCH THIS again, in order not to make it not work, again... :-)