Not always playing from a book.
How to punish a non-theoretical move?
You need to learn to play your own moves in my opinion, and make decisions. At least only not do that in the opening,

The theory gives you the best responses. If your opponent plays something else then he made a worse move. This is why you shouldn't memorize moves until you fully grasp the ideas and motives of the opening. I can't give you anything specific because ideas differ across openings.

The theory gives you the best responses.
Where do novelties come from?
Just because a move isn't the main-line, that doesn't mean that it's a bad move. Chess grandmasters are as fashion-conscious as teenage girls. Some lines are main-lines simply because they are fashionable.
Why else would the Scotch Game have been abandoned for a hundred years and then suddenly become topical again? Or the Berlin? Or the Guioco Piano?

When I study an opening, it's kind of annoying when your opponent plays a move that is non-theoretical, but that looks okay, and that you don't know how to play against. How can I punish those?
Depends...
Depends on the position. But in general you want to do the following:
Develop your pieces to active squares.
Fight for the center.
King safety.
Create threats.
Create weaknesses in your opponents position.

The theory gives you the best responses.
Where do novelties come from?
Just because a move isn't the main-line, that doesn't mean that it's a bad move. Chess grandmasters are as fashion-conscious as teenage girls. Some lines are main-lines simply because they are fashionable.
Why else would the Scotch Game have been abandoned for a hundred years and then suddenly become topical again? Or the Berlin? Or the Guioco Piano?
I don't mean just the main line also popular sidelines. And yes you are right, I am overgeneralizing to prove a point.

I doubt the positions the OP is thinking about are much like the Two Knights line mentioned above. That seems like the opposite of the sort of situation being described. Anyone who plays the 4 Ng4 line against the Two Knights plays that move already having learned something about one of two ways you can punish the infamous 5 . . . Nxd5 error, about which there's tons of theory.
I think the sorts of positions we're talking about are more like this:
3 . . . h6 is the sort of weak but unspectacular departure from theory that you see sometimes. It's often played by people who have gotten into trouble in the 4. Ng5 line of the Two Knights and just don't want to deal with it. But in making a non-developing move in an open position, they're wasting time. So how to exploit it? Develop! Either 4 d4 or 4 0-0 seem quite good, and white should have an excellent game.

The OP is rated 1300 in Daily, so the answer needs to be tailored to that.
1300 makes the top 0.1% of all players so that is something to be very proud about

The OP is rated 1300 in Daily, so the answer needs to be tailored to that.
1300 makes the top 0.1% of all players so that is something to be very proud about
That is amazing. I have no idea if that's true or not, but if it is, it's amazing.
When I study an opening, it's kind of annoying when your opponent plays a move that is non-theoretical, but that looks okay, and that you don't know how to play against. How can I punish those?