Hermione panicked and couldn't think of a better lie.
Saying that she went looking for the troll probably wasn't the best thing she could have said. It worked well enough, since she was able to get both Harry and Ron out of trouble and come out of it with five extra House points. If she was thinking more clearly, she might have been able to say something that would keep all three of them out of trouble, and not get any House points deducted.
Remember, though, she probably wasn't able to think particularly clearly. She was having a very stressful day. She was crying in a bathroom all day because Ron insulted her, then she was cornered by a troll. She narrowly escaped being either hurt or killed and ended up getting saved by the same student who was the reason why she was there in the first place and his best friend. At this point, she wouldn't have been thinking as logically as she normally does, because she was probably in somewhat of a state of shock.
But after Ron and Harry saved her, she didn't want to immediately get the two of them in trouble, so she said the first thing she could think of to make sure McGonagall wouldn't punish them. What she said was effective in doing that, and she didn't get in that much trouble for saying she went looking for the troll.
As for whether the lie she told was the best way to handle the situation, probably not.
There's no reason why an excuse involving her just being in the bathroom at the wrong time wouldn't have worked. Keep in mind, we don't know where all the bathrooms are in Hogwarts. They probably aren't very close together, since Dumbledore mentioned really needing one when he found a room of chamber pots (actually the Room of Requirement). Hogwarts is a big place, so sometimes it would take a while to get where you're going. The students were all supposed to be in their common rooms, but if it would have been a while before she got there, this definitely could happen. It would have probably been better for her to say she really needed to go, so she ran off to the nearest bathroom.
Presumably, there would be available bathrooms somewhere near where they would be keeping the students (though it's never said, I'd expect each House common room would have one), since they might have been there for a long time, but depending on how far away the end point was, someone easily might not be able to make it all the way if they had to go before the evacuation. This is a plausible situation that McGonagall could believe, since sometimes you just can't wait to get to a bathroom.
She also could have said she was in the bathroom during the student evacuation, in this case also blaming some kind of illness like stomach flu/diarrhea/anything else that would make someone spend a lot of time in the bathroom, and didn't realize that there was a troll in Hogwarts and that students were supposed to be in their common room. This is fairly close to the truth, avoids mentioning her crying or Ron insulting her, and keeps all three of them out of trouble.