Lethn
I don't think you need to cast rays here.
I assume you have a box to place on a height map in a 3D scene.
Don't know if this is best practice, but I think you need control over both meshes, the box and the one generated from the height map. Get the bottom surface area of the box to place, then determine the place to put the box and level all the height values, plus a certain rim around them, to the same y value. Don't forget to set values in the source as well, e.g. in the texture, which is probably the most complicated part if Godot doesn't have a functionality for it.
This will create the bottom plate so to say. But you'll have steep (up to 90°) banks in areas where there is now a large step. So set a maximum angle (maybe 70°) to avoid too heavy artefacts when rendering textures over it, or have textures meshes of walls or other earth- or construction works to put there. That'll be content creation.
There's another thing to have in mind: not all terrain rendering has meshes, specially large terrain generates them on the fly each time the player looks at it (oh numerical stability sighs). Maybe think over how to change the box, and not the terrain, add modularized patio and walls/embankments if necessary around it, together with textures. There must be an interface between such models and the terrain renderer to place these things gap-free into the landscape.
I guess that's how Slartibartfast would do it :-)