There are several reasons for this:
Not everyone uses the check-in counter
Not all passengers use the check-in counter. Nowadays with airlines charging more money to check-in luggage, more passengers just carry hand luggage. This means they don't pass the check-in counter but go straight to security. Therefore a check at the gate is necessary.
The check at the gate is a bottleneck
As mentioned in the comments:
Also, the boarding check is a bottleneck. If at all possible, the airline would rather catch problems at check-in.
This is also true. If the passenger is caught at check-in, this will cause less disruption for the airline and other passengers later on.
Avoiding disruption later on
If a passenger is refused to board, his luggage has to be removed and the flight can be delayed by a considerable amount of time.
Delayed flights costs the airline billions each year. The airline doesn't want extra costs.
First of all, not everyone uses the check-in counter. Some only carry hand luggage and proceed straight to security and to the boarding gate.
Checks are also done twice to make sure there are no mistakes, as a mistake can cause the airline a lot of problems. Some people could also have been missed at the check-in counter. It’s like asking why do airline staff check your boarding pass at the gate and on the plane, to make sure you’re not on the wrong flight!
Accepted at the check-in counter but refused at the gate?
This could be because checks weren't done properly or at the gate something came up on the airlines system.