This quote is saying that it is better to be lonely than to be friends with awful people.
A "toxic person" is a person who is bad to be around because they hurt you. This is the kind of person who lies to you a lot; says you mean a lot to them but you really don't; etc. Sometimes a person might end their friendship with a "toxic person", but then get lonely by themselves.
It's better to be alone than with someone who hurts you.