While anonymous access to your Confluence site must be enabled in global permissions, public access to spaces with quizzes does not need to be granted. Therefore anonymous users do not need space permissions to take quizzes.
Enabling anonymous access to your site does not mean that non-logged-in users will be able to browse pages and spaces in Confluence. As long as a space is not publicly accessible (anonymous users do not have space permissions), non-logged-in users will not be able to browse pages and spaces, while being able to take quizzes.