Uncertain graduate study plans due to timing problems with visa and professor's funding
Why he acts like this? 


We cannot know, but there are plausible reasons. Some of my funding is available in the form "use it [in this time period] or lose it." If I have a project like that and a student indicates that it is likely (s)he cannot come, I will give that project to someone else rather than lose the money entirely. Here the prof has to make an educated guess: (s)he wants to avoid the situation you are in, but we have all been let down by students who promised they would come, but at the last moment did not. So apparently your professor made the guess that you would not be able to make it. 


  how can my I make sure that the professor will give me fund after 2 months?


If you have a contract, but apparently you didn't have one, so that suggests that you are from a country where it is common to sign such a contract at the very last moment or where funding is not considered a form of employment and thus there is no employment contract. As you can see that is hugely dependent on the local laws and customs. In those cases, the answer is: you cannot be sure. Since we don't know which country you are in, there is little more we can say.