If the camera is only a component of a larger multi-purpose device such as a smartphone, it would likely not fail more quickly than other parts of that device assuming you didn’t take an ice pick to the lens. Smartphones are obsoleted by being unable to provide new and wanted services (FaceID?), non-support of operating system software, or other reasons not related to camera use. They can also be quickly obsoleted by every marketers wet dream: the “I wanna new thingie” appetite buyers have.
As others in the post, I have some old fully functional cameras: a Minolta and Nikon F both purchased in 1967, both delivering decades of excellent service. One could argue they are NOT obsolete by any mechanical standard, quite the opposite. Yet they are both obsoleted by film products evaporating in the market, and the desire to have instant results without the albeit short delay of Polaroids. Digital photography delivers that, and over time with improved resolution, the quality approaches that of silver nitrate film.
OP asked if cameras are being made to last only 2-3 years. Hardly, the cameras will last far longer than that, witness early iPhone models still in use. I’d bet the cameras on those antique iPhones work just as well as they did the day they were produced in the factory, perhaps with a few more lens scratches though. My iPhone7’s camera is not degraded in any way from the way it worked new, similarly to my wife’s iPhoneSE (1st gen). I have supposedly excellent cameras (plural) in my iPadPro (4th gen) and that’s great I suppose. I’ve had iPads since they came out and have yet to ever take a picture with the device and don’t see that ever changing, but I digress. Our iPhone7/SE cameras work well but have been obsoleted by (a) better ones (b) desire for newer phones for reasons other than the camera, and (c) we have few moose in our city limits.