As noted in the question comments, the kanji was originally . The nutshell version of the article Yang Muye linked is that monks developed a shorthand version of that looked like a box with a vertical line through it: !shorthand version of that looks like a box with a vertical line through it. Over time, the shape of the surrounding box changed, likely due to the same anatomical and mechanical processes that inform any change in handwriting. !enter image description here became !enter image description here, and then that became the modern simplified _shinjitai_ character .
, meanwhile, is a pictogram of a gate. You might run across alternative form , but otherwise, this character is much more straightforward, both in semantic development and graphical evolution.
Ultimately, the resemblance between and is purely accidental, and has much more to do with the constraints placed on kanji shapes and the kinds of strokes used in handwriting.