As the name suggests, middleware is a piece of software that connects two different or similar places. In the world of software engineering, middleware is a software component and is assembled in an application pipeline to handle requests and responses.
These components can also check whether a request should pass to the next components, or whether the request should be handled by a component before or after the next component is triggered/invoked. This request pipeline is built with the use of a request delegate. This request delegate interacts with each HTTP request.
Look at the following quote from the documentation of ASP.NET Core (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/):
"Middleware is software that's assembled into an application pipeline to handle requests and responses."
Look at the following diagram...