How did words like rubbish, ribbon and cabbage get "BB"?
Solution 1:
The spelling bb in rubbish, ribbon, cabbage is not entirely random because it is related to their pronunciations, as Decapitated Soul noted in the comments. The occurrence of a double consonant digraph such as bb is generally restricted in English to the position after a "short vowel" sound /æ, ɛ, ɪ, ɒ, ʌ/ or /ʊ/ (/ʊ/ is rare so I don't think any words actually exist with it before -bb-).
However, the double-consonant spelling pattern was not applied to all words with pronunciations of this type, as there are words like trouble, double, public, publish, robin whose standard present-day spellings do not have bb. Some words of French origin with short vowels were spelled with double consonant digraphs, while others were not; the reasons for this do appear to be fairly random. The Oxford English Dictionary notes old spellings with -bb- exist for double and robbin.
The pronunciations with a short vowel aren't completely straightforward to explain, but do seem to follow a general pattern. In English words from Anglo-Norman/Old French, it is fairly common for vowels in non-final syllables that were originally unstressed in French to be pronounced as short. Other examples are courage, savage, punish, lemon. However, there are also words where a long vowel developed in a similar context (bacon, label). For more detailed coverage of how the pronunciation of words like this developed, you can look at Otto Jespersen's Modern English Grammar on Historical Principles.