Yes, Greedy algorithms give local optimal solution but that local optimal solution may or may not produce globally optimal solution. In Kruskal’s algorithm, it produces.

There are some greedy algorithms which produce globally optimal solution and there are some algorithms which don’t.

Kruskal’s algorithm comes under those greedy algorithms which produce gobally optimal solution.

Why it produces globally optimal solution, for this, you have to go through the proof of correctness of Kruskal’s algorithm. I am mentioning some sources for it:

1) MITOCW

2) Wikipedia

I would suggest to go through the first link because you can understand it easily from there with the use of Cut and Paste argument for greedy choice property.