You get an Oyster card from the machine at a tube station. As for the refund
Oyster Card Refunds
The £5 deposit you pay for an Oyster card is
refundable along with any pre-pay (Pay as you go) money left on the
card.
Before you claim a refund, it’s worth bearing in mind that if you’ve
used your Oyster card on a Pay as you go basis and it’s not loaded
with a weekly Travelcard or bus pass then it’s transferable. And the
money doesn’t expire so you can give it to a friend, relative or
anyone else to use.
If you don’t know anyone who might want to use an Oyster or you don’t
plan to return to London, you can get back your unused money.
Where to get a refund in London
Your £5 deposit and up to £10 of Pay as you go money can be refunded
at any London Underground (tube) station ticket machine
If you have more than £10 of Pay as you go money refunds are available
at TfL Visitor Centres.
If you have an online account with TfL, refunds are available online.
Once you get your Pay as you go credit and deposit refunded you will
no longer be able to use the Oyster card.
How to get a refund after leaving London
If you can’t visit an underground station before you leave, send your
Oyster card and photocopied proof of name and address to TfL:
Oyster Refunds
4th Floor
14 Pier Walk North
Greenwich
London SE10 0ES
Refunds by post will be sent by cheque (£) or by bank transfer to your
bank accounts (UK addresses only).
If you have any questions, contact TfL Customer Services on 0343 222
1234 (open daily 8am–8pm).
Last updated: 5 January 2016
Source