The stability of an infinite-layer compound ACuO2 (A=Sr, Ca) at high temperature was studied by molecular dynamics simulation. For SrCuO2 the infinite-layer structure was well reproduced at 300K. However inspection of the simulated structure revealed that oxygen ions displaced from initially planar CuO2 layer to the c-direction by ±19 pm alternatively. This structure was stable up to 1200K and transformed to an amorphous phase above 1300K. For CaCuO2 the infinite-layer structure was unstable even at 300K. Simulations in which cation in A site was substituted revealed that large cation in A site is responsible for the stabilization of the structure, consistent with the experimental results.