The simple
answer is probably because of "stress". This could be
water, light, temperature, or some other factor. When a plant starts to feel stress, it can get into that mode of "this may be my last chance to seed!"
I usually cut these scapes for eating when I don't want any seed - that seems to help a little.