1. This is the boy whom Mary likes.

2. This is the boy who Mary likes.
3. This is the boy Mary likes.

(Are they all grammatical? When do we use Sentence 2?)

1 and 3 are correct. 2 is incorrect.

The people who use the phrasing in 2 are speaking very casually.