A geodesic is defined to be the curve in the manifold which has the shortest path/length between two points.
But when the curve is closed and the two points are the same then the curve length can vanish in a homotopy sense.
The shortest path is zero between a point and instelf.
So I am confused about what is the definition of a "closed" geodesic.
A geodesic is only the shortest possible paths between two points on it, IF the two points are sufficiently close to each other. The correct value of 'sufficiently close' depends on the manifold and is called the injectivity radius. It can be infinite (for example in $\mathbb{R}^n$) but if there are closed geodesics it is finite.
Edit in response to comment: On the standard sphere, the geodesics are the great circles. If you pick two points on the sphere (that are not directly opposite each other) there is a unique great circle that passes through both of them. There is a short way and a long way around the circle connecting the two points. The short way realizes the distance between them, the long one does not. You could define geodesics on the sphere by the property that for any two points on them at distance less than $\pi$ along the path, the path realizes the distance on the sphere.