I do not have a full solution, but I have a concept that should work:
Part 1: Refilling with cobblestone
This is essentially just a regular cube builder. The cobblestone farm pushes into a row, which gets pushed up to make a wall, which gets pushed sideways to make a cube. I would just recommend to use counters here, to push exactly the right amount of times and exactly with the right timings, unlike normal cube builders, in which you usually power all pistons every time.
Part 2: Pushing the last wall up once and the last row sideways once
This is also pretty easy, just use a row of pistons again to push the last wall upwards and a single piston to push the top row sideways, into whatever area you want to use the soul sand in. But this only works once per wall and row. To fix that, here is …
Part 3: Filling up the last row with sand
To push the rest of the last wall upwards, the only (potentially working) idea I had was to temporarily insert an additional row of sand whenever you push the wall of soul sand upwards. The sand wall falls down on its own while you replace the soul sand wall with it row by row. Once you're done clearing the wall of soul sand and generating a new wall out of cobblestone, you can simply push the cube over as usual and all the sand will return to its old position.
Part 4: Pushing the rest of the last row
The sand method does not work here. So what seems like it would be easier actually isn't really. The only idea I had that does not involve a flying machine is pistons pushing pistons:
From right to left, you always first power the top (sticky) piston, then the bottom (regular) one, then unpower the bottom one and then unpower the top one, then proceed one block to the left. If it's easier, you can also unpower all top pistons at once at the end. Every bottom piston is only responsible for pushing the soul sand row one block further. This also means that you can push it much further than you could with the single piston on the right, so you have more space for wiring in that area on the left.
As a counter, maybe this one or one of these is helpful or maybe something based on this, but less extreme.
Observers at the end of the rows and columns are probably a good way to trigger more pistons, that way you don't need as many counters in total.
Maybe this contraption by Mumbo Jumbo could speed up the machine, it generates an entire row of cobblestone at once.
If you generate stone instead of cobblestone, you can use an Efficiency 5 diamond/gold/Netherite pickaxe and Haste 2 to instantly mine it, that way you save yourself a lot of time and have a much lower risk of accidentally breaking the pistons (because you can quickly swing your cursor from side to side, never resting on a piston for long enough to break it).
And now have fun wiring up this monstrosity!