I think you’re wrong. Obama was for gay marriage before he was against it—while it was politically expedient for getting elected. He’s such an ideologue that making illegals citizens to boost Leftist voting and drag down white Americans suits him just fine. I imagine he sees the good that will come from majority Marxist voters will outdo any bad from Hispanic competition for low-skill, black jobs.
He opposed it to get through the general election (to avoid frightening away centrists who are disgusted by perverts), then had to do a 180 later on; it is an unpopular issue in America, especially in Black America, and it exposed him as a simple stooge of the white liberals.