I'm enjoying just sort of following along with the project.
For a large socket, I've sometimes used short sections of heavy wall exhaust pipe. We have a custom muffler shop in town that makes custom exhausts, and he has a large stock of nearly every size of pipe. He is willing to cut off short pieces and over the years I've accumulated a fair amount of these 1" to 4"long sections of heavy wall exhaust pipe of all diameters to use for just that sort of project. Tell him what you want, and he will cut so that the ends are nice and perpendicular. The heavy wall pipe is more than strong enough. I've even brazed a thick washer to the ends of some pieces specifically for gently tapping with a hammer.
Looking at the pinion gear I hate to say this....but I'd replace it - especially if I had a new or better one. I think that one will work, but it may not last long. Tractors take a lot of stress and I wouldn't want to always be worrying about it.
I haven't looked at the shop manual to see if there is an engagement spec. - which usually means shimming for proper ring-to-pinion engagement. But if there is, I'd be even more inclined to replace them both as a pair. And do the proper shimming. You can buy hardened shim washers by size from a machinery supply - usually McMaster Carr - although our local hardware store carries a surprisingly large stock of hard shim washers.
On the gasket question.... that's worth some discussion on older mechanical projects. use paper gaskets where I can, and even go so far as to wet them and then press them flat until dry if I can find the darn things..... I used to make gaskets but don't since the advent of really good RTV. Back to the paper, after flattening, I coat with a very THIN layer of the best silicon RTV (means Room Temperature Vulcanizing) that I can find and then let that almost completely cure before assembling - but still slightly tacky. The Permatex silicons are good enough for general automotive/MC/Tractor work. Once tacky, the paper gasket doesn't slide around. If it slides, it's too wet.
Right now I've been using Permatex ULTRA GREY Sensor Safe RTV silicone Gasket Maker for doing that.
When I don't have a paper gasket at all, I lean toward Permatex Perma-Shield Fuel Resistant Gasket Dressing & Flange sealant (also an RTV type). It's made just for that purpose.
Permatex also makes a a copper-colored RTV specifically for engines in high heat applications. Frankly, I've used all three of those Permatex RTVs on flanges and they seem to work about the same. Good enough, but there is a whole world of even better Silicon RTVs for commercial and aviation use. More about those below. You might want to consider them...
First a bit about the problem with all and all of these RTVs is that they are really sticky and also slippery when they come out of the tube. The key is to make a thin even layer, and then let them cure until tacky before assembly. AND THE TRICK to doing that is that is that as sticky as they are, they can be smoothed by gently using your finger wetted with saliva to push the RTV around.. That works until you break through the saliva or soap layer and then the RTV starts to stick to your finger. So I keep a whole roll of paper towels right there along with a tub of water and dish soap to keep at least one finger tip clean. Pure water doesn't work as well as spit.
As a chemical family, these RTVs are all moisture-curing type, so wetting them does accelerates the cure rate. Practice on somethng first.
If you just hate the organic acid smell of these RTVs too much to do it this way, there is an even better way which is the commercial and aviation types. These are commercial RTVs available that are also moisture curing, but use a different (platinum) catalyst to begin the reaction. That makes them work easier and they also don't have the acrid odor of the less expensive RTV smelly catalyst types. They better RTVs work the same way but smear much more easily and evenly, cure more reliablly, and last longer. Cure to tacky is in about 30 minutes. However they are way more expensive - but worth it because of how well they work, resistance to most solvents, and extended temperature range. No out-gassing. It's the go-too sealant goo for hi-tech and aerospace. Lots of uses. Non-reactive, non-poisonous.
My favorite in these is Dow Corning 3145 Gray in the 3 oz. tube for $33.00 from Pilot Gear Online. That is enough to do this project several times and if treated right a tube will last for years. IMHO, this stuff is worth the high cost for the way it works and lasts.
Also good for all kinds of weather-proof repair for anything vinyl or rubber which needs to adhere well and stay flexible. Fishing gear, vinyl seats, rifle scabbards.....Comes in clear as well as gray. Gray is easier to apply to flange surfaces because you can see it. I use both.
https://www.pilotgearonline.com/brands/Dow-Corning.html?sort=featured&page=2
Well, that's enough on goo....but you did ask!
OK, nice job on figuring out TBN's arcane but effective photo posting. And I see that you found the hydraulic filter. Yep, it caught the crud and hopefully saved the system. That filter is cleanable and re-usable. BTW, so is the air filter. Yanmar's Operator Manual says to clean the hydraulic oil filter carefully in solvent with a soft brush and gently blow dry with compressed (not hot) air.
I've seen some where the filter material itself was made of wound SS filter mesh, and others that seemed to use a nylon slip on mesh cover. If I remember right, the SS mesh was #600 - this is standard filter material 0 I've posted on that before - the mest itself is available from science houses, our local hardware store, or from McMaster Carr online. if you tear the filter and need to replace the mesh just do so... don't throw that basic filter assembly away no matter how bad it looks. Clean it or repair it. Replacements are hard to find.
I'd expect that you will have to clean it again - maybe several times - in the first hours of operation after this job.
That is the only filter in the trans/hydraulic system. There isn't a replaceable screw-on filter in those older YM155/195/240 Yanmars - although the newer 3 cylinder like the YM186 & YM276 have a replaceable screw on type in addition to the cleanable one.
Hope all this helps, good luck.
rScotty