Technically, if you go on the court without prior authorization it constitutes criminal trespassing and you can get up to six months in prison and/or a $500 fine. But, that being said, presuming nobody else is on the court when you begin (as opposed to running onto the court during a TV timeout, stealing the ball from the ref, and trying to make a layup), you'll just be asked to leave, and as long as you don't refuse, you won't get in trouble. Just don't do it every day, because eventually they'll catch on and arrest you.