How can I prevent Mac terminal ssh from disconnecting when the screen is automatically turned off?
As mentioned by Jakuje in the comments above, I strongly recommend using screen (or tmux) for long running commands or sessions that you would want to resume if disconnected for any reason.

Another approach would be to install mosh (https://mosh.org/) to make the connection. You can use it just like SSH and but it has support for intermittent connectivity (e.g., your laptop going to sleep) so that you can resume the connection without interruption from a user perspective.

However, I suspect your problem is not necessarily from the screen turning off, but from the SSH session timing out due to an idle connection.  You can edit your ~/.ssh/config file and add in an entry similar to the following

host your.remote.host
     ServerAliveInterval 180


which will cause your client to send a packet to the server every 180 seconds if it doesn't receive a packet from the server.