It is not illegal to count cards since the player is not altering the game in any way. The player is simply using the knowledge that is available to all players. However, any casino has the right to ask anyone to leave or stop playing the game, as they feel fit.