The same way ancient sea-beds get pushed up over 20,000 feet high in folded mountain belts -- large-scale movements of the Earth's crust. Plates collide; sometimes they ride up over each other (forming fold mountains) and sometimes they slide beneath each other (creating trenches, like the Marianas in the Pacific). Both create opportunities for rock beds to be buried or thrust up.
There is increasing evidence that the planet manufactures petroleum on a continuous basis. Apparently, bacteria combine it out of residual methane deep in the Earth's mantle. Dry holes in granite in Sweden have ended up producing light crude.
Current tectonic theory holds that the trenches are created by plates receding from each other, not by colliding. The best known place where one plate is being forced under the other is the northwest coast of the U.S. from Gualala to Juneau. This is the engine that fires the Cascades (as in Mount St. Helens)