This is sadly somewhat unavoidable for some people. It doesn’t have to do with fasting per se, but with fast weight loss (or even just weight loss).
You can try adding other supplements (folic acid, for example), but I think the best way is going to a doctor, who will tell you whether your hair loss is temporary or something more permanent, and the best way forward.
Another somewhat sad thing (or maybe good in your case) is that hair loss has a lot to do with what you were doing 3-6 months ago. So maybe the situation will normalize in that time.