I have read many articles stating that the maximal matching of a bipartite graph can be found using max flow algorithm. But there is a possibility that the matching we get from max flow is not maximal or the matching does not have maximum edges.
Example taken from Competitive Programming Handbook by Anti Laaksonen:
But if I present the graph in a different manner such that the graph now is:
Then as the algorithm of max flow progresses the matching would be 1----5, 2----7
because 1 simply erases path to the sink but if it would have gone for the edge 1----6 then the matching could have been
1----6, 3----5, 4----7
I was with you up until this point:
Then as the algorithm of max flow progresses the matching would be 1----5, 2----7
What you're describing here isn't actually a maximum flow in the graph. We could push more flow across by sending a unit of flow from 1 to 6, a unit of flow from 2 to 7, and a unit of flow from 3 to 5.
Reading over your question, I think the reason you ended up with the (non-maximum) flow rather than a maximum flow is because of this statement:
because 1 simply erases path to the sink
From what you're describing here, I'm assuming you're using something like the Ford-Fulkerson algorithm to compute the maximum flow: find an augmenting path from the source to the sink and push flow across it. But Ford-Fulkerson also has a second step here: after pushing flow across an edge, we introduce a residual edge in the reverse direction of the flow pushed. This gives the opportunity to "undo" the decision we made in the event that we find a better path.
As a result, after we push a unit of flow from 1 -- 5, we add in a residual edge from 5 back to 1 with a single unit of capacity. That means that the graph now looks like this:
Here, edges in teal flow from s toward t, and edges in purple flow from t back toward s.
Notice that we can "undo" our decision to assign 1 to 5 as follows. Push a unit of flow on the path
s → 3 → 5 → 1 → 6 → t
to give this flow network:
Now, pushing one more unit of flow on the path
s → 2 → 7 → t
gives the overall matching 1 -- 6, 2 -- 7, 3 -- 5, which is a maximum matching.