Although I understand that if we seperate out the transaction this error gets fixed but my question is how is the work uncommitted and why can't Salesforce do a callout after some records are inserted or updated with DmL. Have gone through many references but I still din get the exact reason
If you make a DML operation, salesforce opens a thread to database or takes one from pool when available.
If the transaction is successful, data is committed and thread is closed.
If the transaction fails, the data is rolled back to previous state and thread is closed.
But when you do a callout, salesforce needs to keep a thread open till the transaction is complete. This is clearly a problem because in worst case scenario the thread has to remain open for 120 seconds (Max timeout of a callout).
Consider this in a multi tenant environment where millions of requests are executed. Keeping a thread open for long time will choke other operations on the database resulting is adverse performance issues.
That is why you aren't allowed to make a callout after DML.
In opposite case, DML after callout, the thread is opened when callout is done, so no issues there.
Another question would be why doesn't salesforce closes the thread after a DML is complete which is answered by Rob's comment.