The UK was “embarrassed” into funding a huge gas project in Mozambique while considering ending overseas support for fossil fuels, a court has heard.