How does iWork for iOS know what account to use for icloud? I saw a student selling a used iPad with the offer of including Pages, Keynote, and Numbers. They said they would wipe the device then reinstall iWork. 

Wouldn't logging in associate the iWork apps with that iTunes account for icloud purposes? If not, how do these apps figure out which account to use?

If I was seing my used iOS device, I would want to be sure that my icloud account isn't on someone else's iPad. Can I be sure that this won't happen?
You can use different accounts for iCloud and the App store by logging in in Settings. For document storage the iCloud account is used.

Keeping iWork apps on an iPad you sell is probably violating the license agreement. And there will be no way to update the applications later because this would require the original iOS App Store password.