The mask is used as part of a disguse that Sam needs to go capture Darkness in Pajama Sam in "No Need To Hide When It's Dark Outside".
At the start of the game, Sam needs to find his mask, lunchbox, and flashlight in order to capture Darkness. To find Sam's mask, he should find it either under his rug or on the coat rack hidden by a scarf. Once he finds all his things, he enters the Land of Darkness.
Unfortunately, he soon gets caught by a snare trap by the Custom Inspection trees and they take away his things since he didn't declare these as his when he entered the Land of Darkness. The mask can be found in two different locations: on Carrot in Darkness' garden or Darkness' living room.
In the Salad Liberation storyline, Sam notices his mask on a carrot in the garden and Carrot reveals himself, stating the mask belongs to the people. Sam states that mask does sure look like his and Carrot explains that he needs to use the mask to protect his identity as the leader of the Salad Liberation Front. The two of them make a deal: If Sam can free Carrot's allies from Fridge in Darkness' kitchen, he will return his mask to him. After Sam tricks Fridge into thinking he will put Carrot into him as a prisoner, Carrot reveals to his allies that he and Sam are allies and they are now free. Before Carrot leaves, he returns Sam's mask to him.
In the Darkness' living room storyline, the mask is in the center of the living room with the dancing furniture. However Sam can't get the mask when he enters as the dancing furniture will jump back into place and pretend to be inanimate, causing the couch to step down on the mask and prevent Sam from taking his mask back (he can't ask it to get off his mask because it will pathetically try to fool him into thinking it's inanimate). Sam will need to make a invisibility potion in Darkness' laboratory, reach the kitchen via the dumbwaiter, and take the mask from the living room while he is still invisible in order to retrieve his mask without the furniture seeing him.
Once Sam has all his things back, he will go to Darkness' bedroom and closet and confront him in order to capture him, however he soon realizes he doesn't need to do that, as Darkness is a friendly character who only wishes to have a friend to play with (he is unable to do this because once he's awake and out, everyone else is asleep).