I solved the issue.
If anyone else has this problem, you need to make sure which WM you're using. Apparently if your WM is Wayland, and RetroPie tries to use X11 to run the game, it won't work. Disabling Wayland solves this particular issue. To do so do the following:
sudo /etc/gdm3/custom.conf
Find
#WaylandEnable=false
And uncomment it by changing it to
WaylandEnable=false
Save, exit, and reboot and Ubuntu will use X11 instead of Wayland and that solved the problem for me. I'm not sure that this is a common problem, and I'm not entirely sure how I ended up using Wayland, but if anyone else has this problem the solution will be here.