This seemingly innocuous question has been on my mind for the past week, so I thought I'd share my thoughts on it and (hopefully) get some helpful insight.
First off, I started by trying to craft a definition of "sandwich" that was as basic as possible. This was "anything surrounded by processed grain" which I immediately found problematic (as I expected it to) because this would include spaghetti and other pastas that we definitely wouldn't colloquially consider to be sandwiches. So I tried to narrow this scope a little bit by redefining a sandwich as something that was surrounded by bread. But this lead to a huge problem because defining exactly what "bread" is was a more complex undertaking than I'd anticipated. For example: do lasagna noodles or cake count as bread? If I restricted myself to only using leavened "breads" that would eliminate matzos, pita, and other such flatbreads. So I scrapped that definition and decided to accept that my ontology would necessarily have to include things like lasagna, pizza, and gyros as sandwiches even though they aren't colloquially considered sandwiches.
I never reached a full definition of what a sandwich was, so I'm opening the question up to you guys to see where we can go. I think this question says a lot about how we group things together and almost subconsciously consider things to follow certain patterns without actually realizing what those patterns are.
Finally, a post for me. I've actually spent a considerable amount of time trying to come up with a basic definition of a sandwich. I ran into some problems too, but different ones than the ones you mentioned. The solution I found most satisfying was defining a sandwich as "a set of ingredients contained between two distinct 'halves' of a bread product." This was the best (and simplest) definition to me for these reasons:
* It excludes wraps, burritos, gyros, and other similar products (violates the 'distinct halves' section)
* It includes sub sandwiches and other sandwiches that have partially connected halves (still 'distinct')
* It excludes toast, flatbreads, and other nonsandwich bread-based foods.
The main problem with my definition is that it excludes open-faced sandwiches. I don't personally consider an open-faced sandwich to be a sandwich, but people that do would probably want to create their own definition. I also initially took issue with defining burgers and hot dogs as sandwiches, but I resolved that by making "burgers" and "hot dogs" subsets of the main "sandwich" set.
I didn't bother to define what bread was. Maybe that should be the next thing I try to do.