By saying that the train will come in forty minutes, Hemingway is creatinig a certain amount of dramatic tension. The issue between the man and woman has to be resolved in forty minutes. He wants her to go to Madrid and get an abortion. She doesn't want to go through with it, and he knows it. She has consented, but he is not sure she won't change her mind. So he keeps tallking to her, tryig to persuade her that it is the right thing to do and that it is a very simple procedure and that it won't change their relationship. Meanwhile the train is approaching, as it is in the classic movie High Noon starring Gary Cooper. A so-called "ticking clock" is a common device in stories.
The fact that the train will stop for only two minutes shows that this is a small, insignificant station. This young couple may be the only passengers boarding here. I believe it is only a way of portraying the setting, although it also suggests the time pressure. They don't have to do anything during the forty minutes the train is approaching, but once it stops they will only have two minutes to decide to get aboard or stay where they are.
In “Hills Like White Elephants, the unnamed American is having a serious discussion with his girlfriend Jig about whether she should have an abortion. This was a dangerous and illegal operation in the period, and the man wants her to go through with it. She does not want an abortion, and is possibly more interested in getting married or at least having some assurance that she will be cared for if she undergoes it. This is a major and serious relationship discussion, and, given how many women died or were permanently injured from illegal abortions, a major life and health crisis for Jig. Having an illegitimate baby in that time would not have been an easy choice either.
Confronted with this sort of huge dilemma for Jig, the mention that the train leaves in 40 minutes and only stops for two suggests that the man is, to put it really crassly, a major jerk. It limits the depth of the discussion and suggests that he’s not willing to invest time in being supportive. Rather than consider that he is the father of the baby and has responsibilities, it suggests that he wants to deal with the pregnancy merely as a minor annoyance that can be handled quickly and superficially.