The escape of molecular hydrogen and the synthesis of organic nitriles in planetary atmospheres