Happened to me once as well. It might be that you didn't see as much activity when your wine was still in the primary as in the first several days, so you measured S.G. and decided it was low enough to transfer it to carboy. However, as you say, the fermentation was still quite active, and that tiny neck of the carboy certainly has a much smaller surface area on which to dissipate the gasses that cause foaming. In other words, all the gas from the ongoing fermentation now had to be expelled from a much smaller opening than the one in the primary, whereby the increased flux of CO2 started generating foam. The foam then rose up to the airlock and condensed back into wine with the help of water or solution that you had in it.
I figured that in such instances it is better to either wait another day or, if transferring to carboy, attach a blow off tube for a day, just to prevent any possible mess.