If a judgment for costs is rendered against the commonwealth, the treasurer of the county to which the costs in such case would have been paid had the judgment been in favor of the commonwealth shall pay it upon the production of an attested copy thereof; but if the costs would have been paid to the commonwealth had the judgment been in favor of the commonwealth, the state treasurer shall pay it upon the production of an attested copy thereof.
Mass. Gen. Laws ch. 261, § 16