Toggles are usually placed in title bars (read headers) in scenarios where you have a singular global control to be manipulated.
Global toggle controls can come in handy if there is a significant probability that the singular control would be frequently required and accessed by the user, or in case the complete application shares the singular control.
This is afforded by the Law of Common Region as the toggle is usually grouped with other global controls such as search and navigation, and would naturally imply to the user that the changes would be applied globally.
Example scenario where a user might need global singular control
If a user can play multiple roles on a platform simultaneously where one role affords the user significant privilege over the other, say an admin who can also double up as an end user on the platform, the global toggle can be used to mitigate any risks of accidental alterations by the higher privilege role.
Mac does this within certain preference menu items, such as Security & Privacy under System Preferences, via the Lock icon that can be toggled to unlock administrative privileges across all the tabs within Security & Privacy.
Example scenario where the application shares the singular control
The dark mode toggle on Google Fonts and many other websites that afford the user to update the language and visual preference to suit their needs is set on the header to bring them to the user's attention at short notice and their clubbing with the global options naturally implies that the changes would be applicable globally.
Having said that, it's also very easy to overuse the global toggles leading to a cluttered interface with barely any cognisance of purpose. Hence, it's highly recommended that you extensively debate over the need of a global toggle—of the lack of it—before choosing to incorporate one.