Pirat it's a library that is used to build Middlewares.
For an introduction into middlewares I'm not sure what to suggest. Stragility's own documentation should give you an idea of what its usage is.
Flarum has multiple middlewares built into core and it works just like shown in Stragility's documentation (except there are a few more). In an extension you usually add Controllers that respond to a given route, and there's already a middleware responsible for dispatching routes to the correct controller.
Middleware are useful in an extension when you want to override or encapsulate the routing stack, for example to create redirects (Example) or to do additional actions where Flarum can't be properly extended (Example).
Using a Middleware in an extension like in my second example should always be a case of last resort in my opinion. Flarum's extensibility allows most things to be extended without hacking into the middleware pipeline.
I hope this helps 😃