Knocking on someone's door and then running off could get you into trouble in some states depending on if the person was there and called the cops on you for doing it.
If it happens just once then they may not call the police and may just brush it off and go back to what they were doing.
But if they constantly notice someone coming up to their door and knocking and then running off and they see you then they may call the cops.
The cops if they are called and catch you will likely just give you a warning for the first time and then the next time you might be arrested over it.
I used to do it when I was a kid and got a warning and then quit doing it.
And I've had kids come do the prank on me by knocking on my door and running or ringing my doorbell and running and to me it's not worth the time to call police and police have better things to do like catching real criminals.
So I don't bother with the police on it.
But others might call the police on you so I would not advise running up to someone's door and knocking and running or ringing the doorbell and running.
The common name for ringing someone's doorbell and then running away is Ding Dong Ditch.
Ding dong ditching is where someone "typically kids" but sometimes adults play a prank on someone by going up to their doors and ringing the doorbell and then immediately running away.
Some people just brush it off while other people may call the cops and report you and if caught you can get into trouble for ding dong ditching.
So I would advise to never do it even though it may seem like fun.
A person caught ding dong ditching may face some fines and have to do community service and if it happens again the Juvenile may be arrested and have to serve a few months in Juvenile detention which is never fun.