Well the UK government isn't really making any money directly.
I believe the design is licenced from the UK based company, BAE. There would also be some sort of payment for modifications,development, localisation for the design. Then some technology sharing and program management costs. Then the builds differ due to the actual build arrangements.
In Australia's case, BAE Systems Australia (the Australian Arm of BAE) ended up buying (or leasing?) ASC Ship building from ASC. So really BAE is now the prime, utilising their now owned ASC entity to build the ships. So for BAE its like building the ship with its (now) Australian workforce. So they pay employees, manage the project, and if they do it well, they get the profits from the build. At the end of the build ASC gets handed back to the Australian government ready for the next contractor.
Hunter Class Frigate Program | BAE Systems | Australia
BAE systems Australia has a fairly lengthy history and wasn't created just recently. They have been in Australia for over 50 years and been buying various Australian based defence companies. They employ thousands of people locally in Australia, across many projects.
However, for the UK, profits and UK based salaries will be taxed. The ships will likely use extensively UK base supply chains, so things like engines (MT30), motors, HVAC, subsystems, and all the little/big dodads you needs are likely to be UK based suppliers. They may select UK sensors and weapons. This does feed directly into the UK economy, and then via tax into the UK government. Some will be sourced from local suppliers where suitable and available, but these might be licence from other UK entities in similar parent arrangements.
Also note on the above diagram, the build is not for 9 ships, but 12 ships before ASC gets handed back...
That is for Australia.
The Canadian build seems more distant, and looks like it will be managed and built by Irving Shipyards. Which is more similar to how the Australian AWD builds were conducted. This proved problematic as who had to fix problems, and wear the costs.
But the choosing of the build does involve significant economic and strategic benefits. With the UK facing brexit, having secure tangible ties to countries like Australia and Canada are extremely important, to the UK and to be seen by other nations.
There are others here more intimate with the process that know more specifics.