I've always taken for granted the fact that units can be treated as variables in mathematical expressions. If you have an object that travels $10m$ in $2s$, you can simply divide the length by the time and get $5m/s$.
This works well and all, but I have started to get a bit uncomfortable with just accepting these mathematical manipulations as valid. It feels similar to treating $dy/dx$ as a fraction in calculus, it does the job most of the time, but it's not quite right.
To try and make sense of it, I went back to the definition of the division: $n/m$ means "how many times can $m$ fit in $n$". If we apply this to the velocity example above, we get: "how many times does $2s$ fit into $10m$". Not super helpful... I've tried a couple of different avenues and nothing really convinces me that treating units as variables is a valid concept. In other words, I would love to be able to understand why dividing $10m$ by $2s$ gives us a velocity. Not only from intuition but by using rigorous mathematical notions.
Just to be clear, I am not confused about how it works. I am aware that if an object travels $10m$ in $2s$ (without any acceleration), then after a single second, 5 meters would have been traveled, thus telling us that the object is traveling at $5m/s$. What confuses me is why we can treat units as mathematical variables (Edit: Variables that are only valid under multiplication/division).
Any help and or references to works discussing these matters would be greatly appreciated!
Edit: Here are some posts about this question that unfortunately have not fully answered my questions.