I was going through blocks on Block explorer and I saw that some of the blocks were containing the miner's name and some were not. What is the reason behind this?
See this sample block for an example.
Blockchain.info has an interesting pie-chart showing the origin of blocks. On that page, they specifically note:
A large portion of Unknown blocks does not mean an attack on the network, it simply means we have been unable to determine the origin.
Blocks do not need to contain any identifying factors. The miner can choose to provide a script in the coinbase of a new block that can be used to identify the source of the block, however they are not required to do so. Another method that can be used to identify the source of a new block would be the target address for outputs of the new coins included in the block; if the address is well-known, then you can be almost certain the owner of that address mined the block in question.
"Anonymous" blocks are simply that, anonymous, in that they have no identifying characteristics.
This question and the answers have some interesting details as a side-effect of trying to identify who mined a specific block.