It is understood the pledge could amount to an extra £55.1 billion cumulatively over the rest of the decade, based on Office for Budget Responsibility forecasts of the size of the economy.
A Scottish Government spokesperson stressed “any wider increase to UK defence spending should not be to the detriment of funding for the Scottish Budget”.
The announcement came after Scottish and Welsh ministers criticised the need to jointly provide the UK Government with £95m from their devolved budgets to fund greater aid for Ukraine.
The funding will make up part of a £1bn pot being provided by the UK to Ukraine for state-of-the-art equipment, including sophisticated air defence systems and thousands of pieces of vital kit for Ukrainian soldiers.
Scottish finance secretary Kate Forbes, whose administration provided £65m of the total, said the funding “must not be seen as any kind of precedent".
“We have become a place of refuge and sanctuary for displaced people from Ukraine, and have done all we can to get help those fleeing the country to escape the violence,” she said in a statement.
“This further funding is to assist Ukrainian armed forces to fight Russian aggression and the unspeakable brutality being perpetrated.
“We have agreed to providing funding on this occasion given the clear need to maximise the international effort to support Ukraine. However, we are clear that this must not be seen as any kind of precedent which leads to devolved budgets being used to help pay for clearly reserved policy areas.”
Asked what discussions had gone on with the Treasury on why the Scottish Government was expected to contribute the money, the First Minister’s official spokesperson said on Thursday: "The UK Government were in touch, as I understand it, [with] all UK departments and the devolved administrations, so us and Wales, basically looking for a contribution from everyone, ourselves included.
"Yes, given the imperative to help Ukraine we are saying yes to this, but the second part is that we don't want this to be the thin end of a wedge which semi-regularly sees devolved budgets used for clearly reserved matters … I don't think it's ever happened before.
"We'd regard it as a one off. We've said yes to it for the obvious good reasons there are to do so, but we don't want it to become a regular thing."
Rebecca Evans, the Welsh Government's finance minister, warned the Labour administration would now face “challenging decisions” about future spending choices.
She said: “We will continue to provide humanitarian support to the Ukrainian people, and it is right the UK should continue to provide much-needed military support. However, defence and foreign affairs are reserved matters.
“This is a novel, worrying and potentially divisive approach by the Treasury – seeking to use devolved budgets, that should be for investment in devolved areas, like health and education, to fund reserved spending areas such as military aid and defence. Funding for these areas should rightly be met by the UK Government.”
A Treasury spokesman denied a precedent had been set were money could be taken from devolved budgets for reserved spending areas, saying: “This is a response to an extraordinary crisis.”
The Scotsman reported last week the Scottish Government had still not decided what to do with £41 million it received from the UK Government to alleviate the cost-of-living crisis.
The UK's total military support to Ukraine since Russia launched its barbaric assault now sits at £2.3bn – more than any country other than the US.
Speaking on the defence spending commitment as the Nato summit in Madrid drew to a close, Mr Johnson said: “We need to invest for the long term in vital capabilities like future combat air whilst simultaneously adapting to a more dangerous and more competitive world.
“The logical conclusion of the investments on which we propose to embark, these decisions, is that we’ll reach 2.5 per cent of GDP on defence by the end of the decade.”
A Scottish Government spokesman said: “Scotland’s diverse military capabilities play an important role in strengthening defence, not just for the British Isles, but also for international alliances such as Nato, so the UK Government must invest in Scotland’s military infrastructure and reverse its decision to cut personnel numbers.
“The Scottish Government urges the Ministry of Defence to act swiftly on the recommendations of the Scottish affairs committee’s recent report into defence in Scotland, which calls for a culture change within its own ranks, and in its prime contractors, with a view to increasing the proportion of Scottish SME spending. Scotland’s SME sector stands ready to add its expertise to UK defence objectives.”
Defence secretary Mr Wallace, who was at the centre of a Cabinet spending row over his high-profile campaign for more cash, was said to be grateful for the announcement.
A source close to the minister said: “The defence secretary has always been clear that, as the threat changes, so should defence spending.
“In 2020 the Prime Minister reversed decades of under-investment in defence and he rightly responded to Russia’s danger by continuing to invest in defence, for which the Defence Secretary is very grateful.”
But Tobias Ellwood, the Tory chairman of the Commons Defence Committee, said it was “too little, too late”.
Mr Ellwood, who has called for 3 per cent of GDP to be spent on defence, also condemned Mr Johnson for going ahead with planned cuts to the size of the Army.
“This is NOT the time to cut the Army by 10,000,” he said on Twitter.
“And moving to 2.5 per cent defence spend by 2030 is too little too late.”
Mr Johnson said the West needed to show Mr Putin it had the “staying power” to support the Ukrainians for the duration of the conflict.
“If you wanted evidence of the amazing ability of the Ukrainians to fight back, to overcome adversity, and to repel the Russians, then look at what has happened just today on Snake Island where Russia has to cede ground,” he said.
The UK has promised an extra £1bn of military aid for Ukraine and Mr Johnson said Volodymyr Zelensky’s country had to be supported to take back occupied territory.
“I think if Ukraine were to be crushed or forced into a bad peace, the consequences for freedom around the world would be appalling,” he said.
Ukraine has lobbied for Nato membership, something which would have guaranteed protection from the alliance when Mr Putin launched his invasion in February.
Mr Johnson said membership of the alliance – which is set to expand to include Finland and Sweden due to decisions made in Madrid – was an argument for “down the track”.
But as an interim position he said Ukraine should be fortified with “Nato-grade weaponry, plus intelligence, plus training” so that a future attack was inconceivable.
The gathering in Madrid also saw Nato take a firmer view on China, saying it challenges Nato’s “interests, security and values”.
Mr Johnson said: “It’s very important that we remember that we have a huge economic relationship with China … but at the same time, we’ve got to understand that there are areas where we need to compete, contest and sometimes challenge what China is up to.
“There has to be a balanced approach and every country around that table can see that, but obviously one of the reasons why what is happening in Ukraine is so important is because there is a clear read-across to other theatres, and that’s why we’re sticking up to the rules-based international system in the way that we are.”
Foreign secretary Ms Truss has argued the Russian invasion of Ukraine shows the need to ensure Taiwan has the arms it needs to deter a Chinese invasion.