There can be several reasons. Bad ground cable or coroded terminals is one. Either of these can happen at the battery or at the starter motor. Another reason is the starter motor. If the bendix system does not operate correctly the starter shaft will not move fully forward to engage the fly wheel, thus causing a grinding sound since the gears are mot fully meshed. Since it does not always do this for you I would eleminate that there are damaged cogs (gears) on the flywheel. But it is possible that the engine start up position might be occasionally at that point. I would suggest removing the starter motor and have it tested. The shaft that moves in and out might by worn or even dirty and not functioning properly.