Note IANANE (I am not a nuclear engineer) but most probably by using a closed Brayton cycle. The gas is heated which expands and drives the turbine, the hot gas is cooled via a heat exchanger, compressed then fed through the reactor again.
https://energy.mit.edu/wp-content/uploads/2017/02/2-3.-HTGR-... has a diagram on page 2 that explains it better than I can