Which STTNG Episode has Riker in the brig at the end?

I seem to remember an ST:TNG episode with Riker jokingly put into the brig at the end. But as Picard (?) is walking away, Riker calls after him, asking if it’s some big joke. What was this? Or am I remembering it wrong?

There are two episodes that roughly fit your description. The more likely one is “Gambit”, a two-parter in which Picard is pressed into service aboard a ship of pirates (though is presumed dead by the Enterprise crew) and Riker gets caught later on, pretending to turn traitor. Data has command of the Enterprise and at the end, Picard suggests that since he is “dead”, he’s going to get some sleep and since Riker has outstanding charges against him, Data may as well conduct him to the brig, which he does.

Similarly, “The Pegasus” ends with Riker in the brig, facing chages relating to a treaty violation some years earlier. The charges, typically, are never heard about again.

I’ll bet it was “Gambit,” then. I seem to remember Riker laughing as if his imprisonment were a joke, but Picard, straight-faced, walks off to Riker’s protests. That doesn’t sound like “Pegasus” to me.

Thanks!