There is a possibility that the behavior may have been witnessed by him. Also, it is not unusual for children of this age to show curiosity about other's body parts and display some sexualized play.
Try not to punish or shame him but rather try to find out what may have prompted the incident. Do not ask leading questions.
If your niece has some more information as to how this started, ask her or her mom. Re initiate to your son what constitute good vs inappropriate touch.