Anomalous thermomechanical properties in glasses include negative thermal expansion, the decrease of the elastic modulus upon compression, and the increase upon heating. The latter behaviour in particular has been experimentally observed for both four- and three-coordinated glass formers. Using MD simulations based on a charge transfer multiple-coordination potential, we are able to reproduce these anomalous behaviours, allowing us to identify the underlying mechanism. Accordingly, when compressing or expanding both tetrahedral and trigonal glasses, mechanically or thermally, these undergo reversible localised structural transitions by invoking buckling-like rotations of oxygen bridges, similar to those responsible for the transformations between different polymorphs of the crystalline counterparts of these materials. We predict that the anomalous behaviour observed in molten boron oxide resurfaces when the glass is subject to tensile deformation at room temperature. Furthermore, the increase of the elastic modulus upon expansion can be traced back to two previously unknown crystalline polymorphs for this compound that we discovered using simulation. Consequently, thermomechanical anomalies have the same origin for both three- and four-coordinated glasses, and this phenomenon appears to be universal for all major network formers.