In basketball, let's say a player is inbounding the ball, tosses the basketball at the referee who’s inside the playing court, and the same player takes the ball back to action afterwards.
It is a good ball or violation?
This is covered by NBA Rules Rule 10, Section III
A thrower-in shall not (1) carry the ball onto the court; (2) fail to release the ball within 5 seconds; (3) touch it on the court before it has touched another player; (4) leave the designated throw-in spot which is one step to his left or right; (5) throw the ball so that it enters the basket before touching anyone on the court; (6) step on the court over the boundary line before the ball is released; (7) throw the ball out-of-bounds without it being touched by a player in the game; (8) exit the playing surface to gain an advantage on a throw-in; (9) hand the ball to a player on the court.
PENALTY: Loss of ball. The ball is awarded to the opposing team at the original spot of the throw-in.
The referee is not a player and does not satisfy the prohibition for clause (3). This is a violation and the opposing team gets the ball.
FIBA Rules are very similar here, and the corresponding section is 17.3.1.