As I was attempting to build the image with sudo the environment variables specified in ~/.bashrc were not there, as by default sudo resets the environment and creates a minimal environment with variables specified in /etc/environment . To bypass this, there is a -E flag in sudo. Thus,
sudo -E singularity build --bind /etc/ssl:/etc/ssl image/python.3.12.2.debian.sif def/python.3.12.2.debian.def
has solved the issue. --bind is still required to access certificates from inside the container.