Referees are in charge of the entire arena when the game is being played. They are allowed to throw coaches, players, cheerleaders, and fans out of the game. They are allowed to talk to coaches, players, cheerleaders, and fans. They can wink, talk smack, and help players off the floor when they fall down.
In most cases, refs are great guys who are unbiased. That is why you never see any of the "talking to fans" going on. Most officials want to avoid conflict at all costs, but they are not going to back down from conflict if someone crosses the line. Are they allowed to talk to anyone they want? Absolutely. There is no rule against it.