This phrase is most likely derived from the old practice of sealing wine bottles with cork stoppers. To put a cork in it would then mean to stop the flow or to plugged up.
It's also possible that the phrase comes from the use of cork as a material for making stoppers for other containers. If something is corked up, it's sealed shut.