Your question is a bit too broad to answer well, but I’ll give a general answer.
It should just normally be based on your pipe code and valve diameter. There are specific reasons for choosing threaded or flanged fittings. Some acid gas lines (thinking of Cl2 lines here), for example, tend to discourage threads at all due to the increased risk of crevice corrosion causing a leak, and forbid threads above a certain diameter.
Again, it just depends on your process fluid, conditions, and applicable pipe code.