At your while loop check make it do this. You want to make sure that you have a way to exit the loop and since you have a counter already you can use that.
So if all objects are used, your code will never exit the loop. Most of the time when unity freezes its because its entered an infinite loop.
If most objects are used, your code will take multiple cycles to exit the loop. Which is a waste of processing time. If your collection is large, this could easily cost you a frame or two.
I would strongly suggest using another collection which only contains the unused objects. Then randomly pick from there. If the collection is empty, then you can return an appropriate error.