A $4.7 million capital gain from a stock sale by former Massachusetts residents is subject to state tax because it stemmed from a business the couple had in Massachusetts, the state Department of Revenue told a Massachusetts appeals court, urging it to uphold the state tax board’s findings.