Yes, but ask your local council.
As this question is in the UK, the law in the UK around ground height is a bit vague but its intent is to prevent inconveniencing a neighbour with a large new structure or being able to overlook their property. Because it's vague you should certainly double check what your local council says just to be sure, but digging down is usually fine (vs. going up, in the form of decking or similar).
A quick summary of UK planning law on height:
- This sort of structure is classed as an outbuilding. Outbuildings like this are often "permitted development" meaning no planning permission is required but within certain limits. The UK planning portal has a convenient visual guide for all the restrictions that apply to a permitted development outbuilding.
The 2 relevant rules regarding height are:
Outbuildings must be single storey with a maximum eaves height of 2.5 metres and maximum overall height of 4 metres with a dual pitched roof, or 3 metres in any other case.
If the outbuilding is within 2 metres of the property boundary the whole building should not exceed 2.5 metres in height.
Given this question is on the boundary, the 2.5m rule applies (as was correctly stated).
So, what about ground height?
Well, here's what the law actually says:
The height of the building, enclosure or container should be measured from the highest ground level immediately adjacent to the building, enclosure, or container to its highest point.
This means you'll measure from the highest piece of ground around the gazebo, up to the tip of the gazebo. It implies that if you dig down, but your building is effectively touching the retaining wall/ sleepers, it can qualify for permitted development on the height rules.