The subject of quaternions is often taught in engineering and physics courses due to its applications in 3D rotations and quantum mechanics. This treatment is often superficial and only presented as a tool. I would like to learn about quaternions in context within mathematics. I would guess that quaternions are covered in some sort of advanced algebra course.
How and where does the subject of quaternions fit into the greater story of mathematics and which courses would be likely to cover this material?
You ask
For the first part of your question, start at the wikipedia entry on the history of the quaternions and other links offered by that search.
In answer to the second part, you are unlikely to find much coverage in any mathematics course these days - just occasional mention as examples.
Their resurgence was prompted by their efficiency at encoding three dimensional rotations for computer graphics applications, so you have to search that literature, perhaps starting from wikipedia: https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation .