Hello, I am a solicitor with 20 years experience I will try t help you with this.
If the owners on both sides f the wall a agree then absent some other reason (eg conservations area) yes it is legal.
Just to be clear, it is the boundary that is my concern. The wall will span both properties so the parties are not on 'either side of the wall', a portion of the wall will belong to one party, while the other portion will belong to the other. The question I was seeking clarification on was whether the fact that the wall will be continuous across the boundary between both properties violates any laws. I know that when you build a fence you must keep it away from the boundary by some distance (6" or 1" or some such thing). So it occurred to me that there might be some sort of law forbidding any one building anything within some distance of the property boundary. Like you would have to leave a gap in the wall around the boundary or some such thing?
There is no law forbidding you from doing this.