Help/ weight gaining

I need help! People generally say that when you lose weight slowly, it remains off, but it seems the opposite to me. Last year I was 205 I didn't go on a diet, but I started paying attention to what I ate. I cut only sugar and coffee, but I still eat everything else, including carbohydrates. Instead of having three slices of pizza, I would take one instead of having cheese and toast, I would only have toast, so I would eat less and healthier. I did it for the sake of health, not to lose weight. But I was astonished that the weight came off so easily. I began in July and in January I was at 174. By April-May, I don't know what happened my weight went up to 184 then 189. I tried working out to at least get back to 174, but nothing my weight kept increasing. Now I'm back at 202 I feel devastated and not even motivated to work out anymore.

What could've caused that? What should I do