碰巧 = coincidence ; things just get right by chance 我在書店碰巧找到這本絕版書
剛好 has the meaning of "just right, just fits perfectly". Example: 這雙鞋的尺寸剛好。You won't use 碰巧 in this case.
In some cases, both apply : 你手機壞了,我碰巧/剛好有隻備用的借你。
碰巧 here means "the spare phone is not particularly prepared for you, it just happen that you are in need of one"
剛好 here means "yours is broken and I have a spare. Everything just fits perfectly!"