Lock the screen automatically when it turns off on Windows

I hate how the lock screen works on Windows. This is perhaps an oversight and for me a security issue, so I’ll share some information on how to make it work better. This applies to pretty much all Windows versions in use today as far as I can tell. By default, when Windows turns off the screen, it won’t lock it. It makes no sense to me why this is the default behavior.