I keep getting logged out when I switch users
As you may know, troubleshooting is a process of elimination and often requires patience. There are a number of things I suggest you try to get to the bottom of this.

1. Bootup into Safe Mode

First of all let's boot up into Safe Mode. Not only can you test to see if the problem is replicated in Safe Mode, but the very act of booting into Safe Mode will run some checks, delete system cache files, verify your startup disk, and attempt to repair directory issues (if any are identified).

Follow these steps to boot your Mac into Safe Mode:


Fully shut down your Mac
Restart your Mac
Immediately press the Shift key and keep it down 
Let go of the Shift key when you see the login window (NOTE: If you have FileVault enabled you may need to log in twice).
Take a note of what happens (i.e. could you boot your Mac okay, is the issue still present, etc)
To exit Safe Mode just restart your Mac as normal


Once you've booted into Safe Mode, let me know how you went. This will help determine if the issue is related to third party software etc.

2. Reset your PRAM/NVRAM

Older Macs had what's called Parameter RAM (PRAM), newer Macs use Non-Volatile Random-Access Memory (NVRAM). It may be worth you also resetting this.

Your question doesn't specify what model of Mac you're using, but all Macs (except for Late-2016 MacBook Pro models) use the same process. I've included steps for both scenarios below:


For ALL models EXCEPT for Late-2016 MacBook Pros


Shut down your machine. Yes, a full shut down, not just logging out.
Press the power button and then press the commandoptionpr keys. You have to make sure you press these keys before the gray screen appears or it won’t work.
Hold those keys down until your Mac reboots again and you here the startup chime.
Let go of the keys and let your Mac reboot normally.



Note: When you log back in you may need to readjust some of your system preferences (e.g. speaker volume, screen resolution, startup disk selection, time zone information, etc).


For all Late-2016 MacBook Pro models (with and without Touch Bar) follow these steps:


Shut down your machine. Yes, a full shut down, not just logging out.
Press the power button and then immediately press the commandoptionpr keys. 
Keep these keys pressed down for at least 20 seconds!
Let go of the keys and let your Mac reboot normally.



Note: When you log back in you may need to readjust some of your system preferences (e.g. speaker volume, screen resolution, startup disk selection, time zone information, etc).

3. Delete preferences

If starting in Safe Mode and resetting your PRAM/NVRAM does not resolve the issue, delete the com.apple.systempreferences.plist and com.apple.loginwindow.plist files.

To do this:


While only logged into your main account and within Finder, hold the option key while clicking on the Go menu
Select the Library option from the drop-down menu
In the Library window that opens up, find and open the Preferences folder
Right-click on com.apple.systempreferences.plist and select Move to Trash
Right-click on com.apple.loginwindow.plist and select Move to Trash
Restart the computer
Empty the trash


Test to see whether this has made any difference to your problem.

4. Create a new user account

If doing all three things above do not resolve the issue, I suggest creating a new user account. However, do not do this until you know the problem isn't resolved. 


Create a new user account
Reboot your Mac as normal
Log into the new account and use it for a little while (maybe some web browsing)
Now try using fast user switching to switch to another account
Take note of what happens (was the new user logged out or not?)
If the new user wasn't logged out, continue to step 7, otherwise stop here and report back
Use the account you're now logged into for a while
Now try fast user switching back to the new user account
Take note of what happens (was the old user logged out when you switched back to the new user account?)
Regardless of what happens at Step 9, now try using fast user switching to switch to another account
Take note of what happens (was the new user logged out or not?)


After doing the above, report back on what happened at Step 6. If you progressed further, also report on what happened at Steps 9 and 11.

If you found the problem was not replicated in the above 11 steps, then use your computer normally (but do not delete the new user account you created). If the problem reappears, then start using the new user account instead for a while as your main account and see whether the problem returns.