Religion is a personal choice, and protected. Sexual orientation is not protected by law.
They could have gotten a cake if they had been willing to get one that didn't specifically express the homosexual nature of the wedding. The baker had no problem selling them a generic cake, the issue was that he didn't want to make a cake that expressed a message he disagreed with.