fence mesh duplicates along mountain plane
You can use Animation Node to create a spline that follow the surface of the terrain and then deform the mesh on it just as you described.

First, create a curve that define the path of the wall, sample some points on it, ray cast them on the terrain, create a new spline from those projected points:



The same applies for the any spline, a circle for instance: