Influence of magnetoelastic coupling on the formation of a spatially inhomogeneous phase in two-dimensional ferromagnets