I was trying to paste some pattern that I made inside another layer. But each time I pasted, it ended up on the layer selected instead of its layer mask even when mask was selected.
I have Photoshop CS5.
Should work when the layer mask is selected, alternatively, try
If you'd like to edit a layer's mask, the Channels Panel is a great place to do it.
Adobe help: About masks and alpha channels
Bitmap layer masks are alpha channels, and they appear in the Channels Panel. You can edit them directly from the Layers Panel, but you see everything composited, so it can be a little trickier to understand what's going on.
It may be worth becoming familiar with Clipping Masks, too. They're very handy and allow for things that aren't easily possible with Layer Masks.
PSDTuts+: What is a Clipping Mask then?
simply select your layer mask before pasting ( click it in the layer panel )
As it's considered like a greyscale layer you can edit it with any tools as a normal layer.