How to tell a Mac to show 4k resolution or higher resolution even when it is not connected to such display?
It depends on which 4K you're referring to; if you're talking about the "actual" 4K (4096 × 2160), then: no (though you can come close).

However, if you're talking about the UHD 4K definition (See the link to Wikipedia above), which is 3840 × 2160, you can do it using 3. party utilities such as QuickRes (paid), SwitchResX (paid), or Retina Display Mode (free).

I've used QuickRes for a couple of years and definitely find it worth the $5. It's also the app I used to test.

Keep in mind: this only applies to the 15", the 13" can "only" display up to 3360 × 2100.