The origin of strain-induced ferromagnetism, which is robust regardless of the type and degree of strain in LaCoO3 (LCO) thin films, is enigmatic despite intensive research efforts over the past decade. Here, by combining scanning transmission electron microscopy with ab initio density functional theory plus U calculations, we report that the ferromagnetism does not emerge directly from the strain itself, but rather from the creation of compressed structural units within ferroelastically formed twin-wall domains. The compressed structural units are magnetically active with the rocksalt-type high-spin/low-spin order. Our study highlights that the ferroelastic nature of ferromagnetic structural units is important for understanding the intriguing ferromagnetic properties in LCO thin films.