The issue is that the set of fixed rank matrices (be they psd or not) is an open set.
Say M is the set of matrices of rank exactly r.
If you optimize f over M but the true optimum of f actually has rank strictly less than r, then the sequence of iterates will tend to that lower rank matrix, which means it "wants to leave the manifold" and things break down.
Practically, what happens is that you represent the rank r matrix as LR', with L and R having r columns. If LR' get closer and closer (as you iterate) to a matrix of rank less than r, then either L or R (or both) must become close to rank deficient. This will translate into L'L and/or R'R being close to singular.
So how do you fix it?
One way is to pick r such that the optimum has rank r (or more): then, there is no incentive to get close to the open boundary and we stay away from singularity.
Another way is to regularize f, to favor rank r matrices. One way to do this is explained here:
Low-rank matrix completion by Riemannian optimization
by B. Vandereycken
See section 4.
but it can be adapted to other geometries as well: it's just an extra term in the cost function.
Best,
Nicolas