Garp taught Luffy how to be a marine and uses that knowledge to break into a government facility
Garp wanted Luffy and Ace to be Marines, so he taught them what a good marine should know and how to do it. While Ace and Luffy obviously didn't become marines, that knowledge was, literally, pounded into their heads. With Ace captured and set for execution, Luffy uses that knowledge to bust his brother out of prison.
Or: Why Garp shouldn't have taught an upcoming rookie what Marine codes meant because all it led to was the chaos a pirate could use it for.