Card counting is NOT illegal under federal, state and local laws in the United States as long as players don't use any external card-counting device or people who assist them in counting cards. In their effort to identify card counters, casinos can ban players believed to be counters — sort of.
Why is counting cards considered illegal?
Card counting is frowned upon because it violates the UNWRITTEN "law" (that the casino is supposed to have the edge).
Why you should never count cards?
Blackjack basic strategy and card counting are hard skills to master. Even if everything goes right, the profitability from card counting is small while the swings can be brutal. You're not going to be able to play long in any casino, otherwise you're going to get caught. So get ready for a lot of travel and scouting.