Many-body spin physics with quantum gases in a confocal cavity