There could be a number of reasons why youre getting sent back to the lobby, including but not limited to:
1. The server doesnt exist
2. You're not whitelisted
3. The server is starting up and wont allow players to connect yet
4. You're using unsupported mods in a forge/fabric server
5. Unsupported minecraft version