While swap will help in many cases, it's not bulletproof. Swapping could hang the system long enough for something to time out. To determine if it's actually a RAM issue it would be best to test on a system with more memory, so if you happen to have a Pi4B with more RAM, testing with that system could be helpful. If you don't have another Pi4B, ZRAM might help.
Other random suggestions and thoughts...
- Pi computers don't consume much power, do you really have to shut it down at night? Try removing that timer switch and disabling the cron job shutdown to see if the system stays up (at the very least it might crash faster making troubleshooting less time-consuming).
- Again, probably not helpful to you, but my personal opinion is that mechanical power switches on the low voltage side are a bad idea. Not only is low voltage less able to overcome resistance that develops over time and use as the switch accumulates dust or tarnish on the contacts (or they wear out), it also doesn't stop the "ghost load" of power supplies that are not in active use. Disconnecting from the high voltage mains side with an outlet tap switch (or switched power strip or surge protector) resolves both of those issues.
- I also agree that a reboot would not cause random login prompts to appear. It must be a service restarting and not a full reboot (which you seem to be thinking now as well).