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 alt+click the layer mask to access the b/w mask directly and then paste.
If you'd like to edit a layer's mask, the Channels Panel is a great place to do it.
Masks are stored in alpha channels. Masks and channels are grayscale images, so you can edit them like any other image with painting tools, editing tools and filters. Areas painted black on a mask are protected, and areas painted white are editable.
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.