Transferring PhD departments
I can't balance your options for you, of course, but I'll give you a couple of things to consider if you haven't already. 

One is the time to completion of your current degree project. If it is soon, then staying might be best and then moving gradually into your math studies, either formally or informally. 

But another option than the one you mention would be to ask around to see if you can't find an additional advisor in math and work with both of them at the intersection of math and CS which you seem to be interested it. This pretty much assumes that you are not yet deep in the weeds of your CS doctoral research. You might be able to avoid the math qualifiers that way if you have already qualified in CS. 

I would guess that there is already some collaboration between the departments at an institution such as you describe. You might be able to explore it painlessly without needing to make an immediate decision or burn bridges. 

What would be on your credential when you finish would depend on a bunch of things, of course.