Why can the BGP protocol be implemented across routers?
But the OSPF protocol can only be implemented on directly connected routers?
Is the OSPF protocol based on IP? we know the BGP is based on TCP, so is this affect that?
OSPF was designed as an internal gateway protocol, to chose the best path in a network under your control. It would not make sense to connect non-adjacent routers, so that feature is not part of the protocol.
BGP can be used at the edges of an autonomous system with intervening routers in the middle. So it can peer with non-adjacent routers.
BGP is EGP(Exterior Gateway Protocol). OSPF is a IGP(Interior Gateway Protocol).
Therefore BGP use to exchange route table information. It can implementing Inter AS routing. BGP Use in Large network environment.
OSPF use to intra-AS routing. Not Inter As Routing.
BGP runs on TCP(179), doesn't rely on the underlaying protocol.
However OSPF works on layer 3, IP layer. (both routers have to have interface in a common subnet)
For a BGP you must have a network to run on. And actually eBGP neighbors must be also in a same subnet by default.