In the case of Ueno, the JR station and the park were both built before Keisei came in, so the only way to get another station in Ueno was to tunnel under the park. Incidentally there used to be another underground station between Ueno and Nippori, which is now a museum of sorts (
https://en.wikipedia.org/wiki/Hakubu...utsuen_Station).