Massachusetts’ taxation of a $4.7 million gain from a stock sale wrongly commingled the business of a former resident taxpayer with that of a company he owned, he and his wife told a state appeals court.