It looks like you've screwed the latch into end grain there. I would not expect that to be a lasting solution. Were you to turn the wooden block through 90° in the vertical axis, I would expect that to be more robust.
ETA - you may need to screw two blocks of wood together, in that orientation, in order to clear the white pipe.
Yeah, it's not 100% perfect, but it was an offcut that a friend who is a joiner gave me for free. As such it was IMO far better than my next best alternative of buying a fence post and then sawing it down to size myself.
It looks like you've screwed the latch into end grain there. I would not expect that to be a lasting solution. Were you to turn the wooden block through 90° in the vertical axis, I would expect that to be more robust.
ETA - you may need to screw two blocks of wood together, in that orientation, in order to clear the white pipe.