Education secretary John Swinney announced the move and said it was “in light of updated scientific and health advice”.
The new rules mean pupils in S4 to S6 and their teachers must wear face coverings at all times including while in classrooms and while moving around the school or in communal areas.
This applies to areas in Level Three and Four and will come into force from Monday, affecting much of the country.
The Scottish government added that face coverings should be worn by adults “at all times” when two metre social distancing is not possible, with parents and other visitors expected to do the same across all restriction levels.
There is also updated advice to children and teachers considered at high risk to Covid-19.
Deputy first minister Mr Swinney said: “Keeping schools open remains our priority but that can only be the case if schools are safe. There have been tremendous efforts applied by staff and pupils to ensure this is the case and I thank them all for their efforts.
"We constantly review the guidance on school opening along with our local authority partners, trades unions, parental representatives and other stakeholders to ensure we are taking all the necessary measures to ensure our schools are safe.
“None of the levels in the framework require any automatic move to school closures or blended learning. However, no one can predict what the coming weeks and months will bring.”
The move was met with mixed reactions from teachers, parents and politicians.
One teacher, Kevin Tweedie, who has hearing difficulties and relies on lip reading for much of his teaching said he was “very anxious” about the new rules.
Mr Tweedie said he backed the public health reasons for the move and that he supported any health measure deemed necessary, the change has impacted how he teaches.
He said: "It is going to be very difficult now for me to make out what my senior pupils are saying in class.
"I have found this to be the case when the odd pupil decides to wear a mask currently, and it actually has put me off asking those pupils questions which obviously is very unfair on them as it is totally their choice to wear a mask and could be impacting their feeling of inclusion in my classroom.
"I feel terrible knowing I am actively avoiding asking them to contribute verbally but it is solely down to my deafness. With all senior pupils now required to wear masks, I am very anxious about how this will go come Monday.”
Scotland's biggest teaching union, the Educational Institute of Scotland, said the strengthening of measures was welcome but “dissatisfaction” remained on how social distancing is meant to work.
The EIS’s general secretary Larry Flanagan said: “The proposed mitigations at Level 4, essentially face coverings for senior pupils, are inadequate.
"The EIS is clear that Level 4 should trigger an automatic consideration of moves towards blended or remote learning.
"Schools cannot stay open at any cost; the safety of pupils and staff has to be the priority, especially those with increased vulnerabilities. In the event of any Council area moving into Level 4, the EIS is likely to consult affected members directly on their views.”
One parent’s group, UsForThem Scotland, said they suspected the decision to force some children to wear masks was made “on a whim”.
Jo Bisset, organiser for the group, said: “Parents suspect this decision has been made on a whim, and is merely just the start of an escalation which will eventually see all pupils forced to wear masks.
“It will be incredibly uncomfortable for young people to spend several hours a day in a mask, and could impact on their learning and education.
“We’re now months into this situation and the government has had ample opportunity to assess what impact its previous mask guidelines were having.
“The failure to do so only heightens suspicion that this is a rushed decision which has been arrived at without proper consideration.”
The main criticism from opposition centred around the fact the announcement of the new measures was not made in Holyrood and lacked a proper debate.
Scottish Conservative shadow education secretary, Jamie Greene MSP, said: “Once again, significant Covid-19 restrictions are announced by the SNP government hours after parliament closes. Had they made this known on Thursday, this could have been properly debated.
"Parents across Scotland understood the guidance around staff wearing masks in schools, and older pupils wearing them in public areas, but the SNP has not explained why this latest move is necessary.
“Nor have they addressed legitimate concerns about pupils' wellbeing, particularly for those with additional support needs."
Daniel Johnson, the Scottish Labour MSP, echoed the concerns on scrutiny.
He said: “This may be a sensible decision, but surely it should have been announced in parliament along with clear evidence of their efficacy.
"Throughout this pandemic the Scottish government has announced pivotal changes to guidance and lockdown measures through press release and off the record briefings, this is simply not good enough.”
Scottish Greens education spokesperson Ross Greer welcomed the move but called for more regular testing of staff and older pupils.
He said: “Teachers were promised their health would be protected by robust social distancing, despite it being obvious that this would be impossible in most school settings. And they were told that ‘enhanced surveillance testing’ would be fully operational by October, but the Scottish Government still won’t confirm if that’s the case.
"School staff deserve far more protection than they’re currently getting. It’s time for ministers to look again at the eight proposals the Greens produced in June, including regular testing in schools.”