software-properties-gtk option "Source code"
I recommend this for the desktop:
software-properties-gtk
then under the "Ubuntu Software" tab click "Source code":

This has added some deb-src lines under /etc/apt/sources.list, and now I can do sudo apt-get build-dep <package>.
I've couldn't find a clean CLI method so I create this bug report for it: https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1802718
Tested on Ubuntu 16.04 to 18.04.
CLI method
I recommend this for Docker images. Since Ubuntu 24.04 you need:
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources~
sudo sed -Ei 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
and before 24.04 that it was:
sudo cp /etc/apt/sources.list /etc/apt/sources.list~
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
Then after changing the configs in either case:
sudo apt-get update
Tested on the Ubuntu 18.04 Docker image. After this change, I can successfully do for example:
sudo apt-get build-dep hello
and before the change it failed with the error:
E: You must put some 'source' URIs in your sources.list
Previously mentioned at: https://askubuntu.com/a/1011675/52975 go and upvote that answer.
Note however that the /etc/apt/sources.list file contains lines such as:
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner
which means that the above sed would enable sources but not non-sources for some types of repos. I don't think that it matters much though.