This phrase is increasingly popular among social liberals (although conservative pundits occasionally use it). It's equivalent to other idioms like "if you can't beat 'em, join 'em."
I doubt liberals who use this phrase really think about the logic behind it.
i) To begin with, it's a recipe for amoral pragmatism. Back the winning side, whichever side that might be. Do social liberals really believe that? What if the Supreme Court reversed Roe v. Wade. Would they switch sides on the abortion debate?
ii) There's also the quality of a self-fulfilling prophecy. You can make something a lost cause by premature surrender. Sometimes you create the outcome by prejudging the outcome, then adapting to the imagined outcome.
iii) The motto is tautologous. History is whatever happens, for good or ill. Better for some and worse for others. In that sense, there is no right or wrong side of history.
By that logic, whoever won the last war is on the right side of history. When whoever won the last war loses the next war, that suddenly puts him on the wrong side of history–unless the next reversal. Outcomes oscillate.
iv) The culture wars don't have decisive winners or losers. Both sides gain ground and lose ground.