Functor and comparator function

at what time we should use functor and at what time we should write comparator function

See Comparators are functors itself. Comparator is used when we need to do some comparison to keep things in order only.
You can use functors everywhere, there is no rule that prohibits its use. (Actually, functors is not defined in Standard language itself, so there might be some slight variation in how people use it. )