That o-ring at the shoulder seals the unfiltered sump side, from the cavity containing clean oil that will be sucked to the hydraulic pump.
Your new filter matches the original and replacement filters in my YM240 (YM2000).
I've found a thin, and dried, bead of silicone sealer on the triangle plate is sufficient for sealing the plate so the sump doesn't drip to the ground. Your lower o-ring would be more convenient for periodic maintenance but this bead of sealer does the same thing.
Your used filter doesn't look bad. Here's what real neglect looks like!
When I bought the YM240 in 2003 I spent a month correcting a lot of severe neglect. This filter was strongly cemented in place and I tore it getting it out. The o-ring at that shoulder was wrong, it was too fat so the metal part got dimpled, and it was made of something that became hardened glue.
I got a new filter from Hoye, flushed the transmission with diesel and wiped out crud from the sump with a rag, and put in fresh fluid.
10 years later I replaced the hydraulic fluid a second time and the filter looked about like your used filter, it cleaned up easily. I took the filter out again last year for an axle repair. The filter and sump were pretty clean and the fluid looked pure so I rinsed the filter, wiped the sump, and re-used the 6-year-old fluid.
The hydraulic system has always worked properly despite its early neglect. Your used filter looks nearly pristine compared to what I found!