Why can't my laptop stay connected to WiFi when locked?
All right, so I've figured out a way to do it. I tried using the command pmset displaysleepnow, and it works as intended. The additional thing is that you have to go to System Preferences > Security &amp; Privacy > General and require a password immediately after the computer display goes to sleep. I then set up an alias:

alias lscreen='pmset displaysleepnow'


and it works as intended. I use the terminal a lot, so lscreen is an easy way for me to lock my screen and come back with my screen being locked but both my WiFi and VPN still connected.