The limiting factors for docked vessels is typically fuel decomposition time and losses due to outgassing or leaks while for non-docked vehicles it's consumables1 being, well, consumed.
In the case of the former, take Soyuz-MS. As mentioned in a previous answer, in normal use it is limited to 210 days docked due to the decomposition of its Hydrogen Peroxide attitude-control fuel into water and oxygen. Note that often (such as with Soyuz-MS) the limit is a soft one and not a hard one. In the Soyuz-MS example, the craft can still function (i.e. return to Earth nonlethally) but in a highly suboptimal fashion (unguided ballistic reëntry).
Note that often there's a bit of flexibility in the limetimes especially if there are no plans for the vehicle to be recovered. HTV-7 (an H-II) with a published maximum docked lifetime of 30 days actually reëntered after being docked at the ISS for 41 days; it is possible that this was due to unpublished design improvements.
Pure conjecture on my part: It is possible that the on-orbit lifetimes can be extended by devoting a larger fraction of a craft's payload to fuel. The more fuel initially launched, the more that can be lost to outgassing, decomposition, leaks, etc. This would explain the huge ranges for the Cygnus and Dragon lifetimes.
1 Station-keeping fuel for uncrewed craft. For crewed craft typical consumables are Hydrogen (for fuel cells), Oxygen (breathing, fuel cells for power and water), Oxygen candles (for breathing, when applicable), and CO2 scrubbers. Note that Hydrogen in particular is also highly prone to outgassing losses via diffusion through container walls[citation sought] and potential tank failure due to Hydrogen embrittlement.