Why did Mycroft give Sherlock's information to Jim Moriarity in S02E03? What did he get in exchange?
Mycroft's revelations were partially accidental.
His government agency had arrested Moriarty in an attempt to interrogate him given the secret he claimed to have that would unlock any door or any computer. He refused to talk to anyone except Mycroft and the only way Mycroft could keep him talking was to reveal things about Sherlock. In these conversations he gave away details about Sherlock's past which might have seemed inconsequential at the time given what he thought Moriarty possessed.
Given how Mycroft looks when he explains this to Watson, he knew it was not a worthwhile exchange. Moreover, in retrospect Moriarty's secret was completely fake (though it seems convincing enough that governments and criminals took it seriously). In fact, the whole episode was probably a set up by Moriarty to get exactly this information from Mycroft so that Sherlock could be discredited. This is only hinted at by the script but is clearly meant to point at the immensely clever and machiavellian nature of the antagonism between the two arch enemies (and possibly that both are, in the end, cleverer than even Mycroft).