Basically, during the creation of Gensokyo all kind of youkai were "invited" to enter, including the nine tailed fox - a symbol of destruction and bad omen. Yukari obviously didn't want to just let it in and ruin her masterpiece. So she got herself a convenient little kitsune shikigami to use as a trap for the big fox. Poor Ran ... But then Suika reminded Yukari about Yuyuko's fate, which ironically resembles Ran's ... So Yukari was like "Meh, I'm getting too soft" and instead of using Ran as a tool, she decided to keep herself a pet.