It's just the way it goes, OP.
I work in professional services BUT as a permanent employee of a company (company A using your description). It means I'm paid a salary on PAYE with car allowance, good pension, holiday pay, health, etc, etc.
The client I'm currently working for pays £1,600 per day for me for a 100 day contract, but this is discounted by 15% due to the number of days. So it's £136k for the total contract.
There are performance clauses in the contract but if they're invoked it pretty much means the rate for the work completed so far reverts to 100%, which tends to encourage clients to see projects through, usually, unless something is drastically wrong.
The crux of it is that I'll complete the 100 days of work over 6 months, taking into account holidays etc, and my salary over 6 months isn't much more than half of the £136k my employer will invoice. So even if I don't work for the rest of the year the company still break even as I'll have already billed a full year's salary.
I could choose to go it alone and bill the client myself - a former colleague does exactly that and their day rate is no different to what we bill - ie £1600/day give or take discounts. They're doing it that way because they want to take several months off to travel each year.
They take the risk of not working for a long period, plus no sick pay, car, bonus, health, etc, etc.
You can't have it both ways.
By the way, I also think one of the companies - either A or B - has got IR35 in mind here.
I've been advised by a lawyer who specialise in this area that even though my employer is completely out of the U.K. (no UK business exists at all) I would be considered a 'disguised employee' if I tried to invoice my employer as a contractor rather than work as an employee. I'd be liable for both employer and employee's NI, etc. They just don't care that it's a foreign company - if you have one source of income you're likely to be caught up by IR35 regs, regardless.
I do feel for you regarding having no income very soon, and no way to pay the mortgage, which is worrying, but I'm very surprised you're in that position as a contractor. When I've worked in that way in the past, I've assumed at least 3-months with zero income is very, very likely to hit at some point.