Hi to all, first post although I've been reading the forum for a few months.
I recently changed the gearbox on my 03 TD5 130 and after putting it all back together it like yours would turn over but only start when it felt like it.
plugged it into a diagnostics computer and no problems, so i changed the crankcase position sensor - thought i might of knocked it changing the box, no change.
next I changed the airflow sensor, still no change.
then I read on the interweb about starter motor problems on the TD5 sometimes causing starting problems, having already done nearly £100 on the other 2 sensors I found a starter motor refurb kit on fleebay for about £10 plus a couple of quid postage,
so ordered 1 and having fitted it after having to drill and retap 2 out of the 3 screws holding the end cap on the starter put it all back together and back to normal starts first time everytime.
the old plunger and contacts were badly arc damaged so i guess when I undone the bolt holding the positive lead it must of moved creating the starting problem.
may be worth having a look at yours.
Adrian