RMBP outputs 4k@60Hz ONLY when lid open
Solved!

The solution is about as weird as the problem. To enable 60Hz in clamshell mode, I had to Option-click the "Scaled" radio button on System preferences' Display resolution screen, then the Refresh Rate option became available and I could switch from 30 to 60Hz. For some reason it wasn't enabled by default when lid closed.

EDIT: Also found out that for some reason this issue is directly connected to my old USB hub. When the display is connected and working at 60Hz clamshell mode, just touching the computer surface with the USB connector lights up a small white spark and the display immediately switches to 30Hz and the option disappears. And this ONLY happens when the lid is closed.

This is easily the most interesting problem I've had with a mac in many years.

*throws the USB hub to trash immediately*