The Canon EOS 4000D and the Canon EOS 1300D seem to me to have the same specs and mount the same lenses, but the second one is cheaper. Is there any risk in buying a camera which is going to go out of market soon? Since you can mount the lenses of the new one, I can't see any risk. What am I missing?
TL;DR: There is no risk in buying older generation Canon body.
Canon is known for the consistency of lens mounts and compatibility. They have 3 mounts for photography right now, 2+1 actually.
EF lenses can be used on EF-S bodies directly, not vice versa! Other combinations are possible with proper reduction rings.
Both your bodies use EF-S mounts so there is no risk at all by using the older body. If I read the Canon designations right, the second one should be higher tier body (when same generations are compared) which compensates the differences in running-in and running-out bodies (when same tier is compared). In other words, new EOS D1xxx should be slightly better than EOS D4xxx. It is possible, that the D4000 is sligthy modified D1300 design, therefore the same specs.