Soooo...I read somewhere to throw a bean bag or something similar on the floor to create a noise when they don't listen, and then praise+treat when he sits.
As you've noticed, not such a good idea. If you need something to distract him from being naughty (charging the cat, putting paws on the kitchen counter, etc.) that might be a fine approach, but not for simply not obeying an obedience command.
Well he is fine with them (inside the house, no distraction, treat motivated) but every once and a while he won't do it. I know he knows what sit means, he just doesn't sit.
This is the most important part of your post - just because he understands a command in one place under one set of circumstances, doesn't mean he's generalized the command to all places and all circumstances, especially if you're talking about the difference between a low distraction environment such as in the house vs a high distraction environment such as outdoors in the yard. There's just no way a 5 month old really "knows" all those commands in the way you think he does.
If you usually train toe to toe, with him facing you, try training with him next to you in heel position. Will he obey the sit command when you're sitting on the floor, or a chair or laying on the ground? How about if he's in the car, or with your back turned, or you're standing on a chair or laying in bed? How about in the kitchen, the bathroom, the garage, your front lawn?
To us, it's all sit - plant your butt immediately. To a dog, it's all different. And once you've got your commands generalized to a variety of circumstances with few distractions, you can expect to start all over when you work in more distracting circumstances. One line dog trainers hear all the time is "but he does it perfectly at home!", and that's because the dog really doesn't get it yet, or is too distracted to really focus.
To fix this you could try "capturing" behaviors for a while. This is something I do a lot of with a new puppy. I wear my treat bag all the time and have a clicker attached to it or wear it on a wrist coil (you can use a verbal marker such as "yes!" instead). Every time puppy does something I like I mark it and toss a treat. Pretty soon puppy is offering up all sorts of great behavior because it's been so heavily reinforced, and at that point you can start adding your commands - say "down" right before you see he's about to lay down on his own, mark/treat, etc.. I mark and reward looking at me (will become the "watch" command) laying down, coming towards me (will become a recall), anything I like. Puppy isn't disobeying commands because I'm not giving any yet.