That’s because with pages they either show or don’t show – if you don’t want it to show on a page, you can just not add a featured image.
For posts, the featured images shows in blog excerpts and on the single post – so if you don’t want it on single posts, that code works great.
For pages, the featured images just show on the page. If you don’t want them to show on the page, you can just remove it/not add it in the first place.
Let me know if that makes sense or not π