Following code will do that functionality. Like how we are renaming a file through UI, we have to first check-out the file and after renaming the file we have to check-in it.
SPSite oSite = new SPSite (“http://<sitename>/“);
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists[“Shared Documents”];
SPListItem oListItem = oList.Items; //taking the first list item
oListItem[“Name”] = “xyz”;
oListItem.File.CheckIn(“file name has been changed”);